package com.review.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.review.project.domain.ProjectData;
import com.review.project.domain.ReviewProject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.review.common.annotation.Log;
import com.review.common.core.controller.BaseController;
import com.review.common.core.domain.AjaxResult;
import com.review.common.enums.BusinessType;
import com.review.project.domain.ReviewProject;
import com.review.project.service.IReviewProjectService;
import com.review.common.utils.poi.ExcelUtil;
import com.review.common.core.page.TableDataInfo;

/**
 * 项目Controller
 *
 * @author ruoyi
 * @date 2022-03-13
 */
@RestController
@RequestMapping("/system/project")
public class ReviewProjectController extends BaseController {
    @Autowired
    private IReviewProjectService reviewProjectService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReviewProject reviewProject) {
        startPage();
        List<ReviewProject> list = reviewProjectService.selectReviewProjectList(reviewProject);
        return getDataTable(list);
    }

    /**
     * 查询我的评审数据列表
     */
    @PreAuthorize("@ss.hasPermi('group:group:list')")
    @GetMapping("/selectTask")
    public TableDataInfo selectTask(ReviewProject reviewProject) {
        startPage();
        List<ProjectData> list = reviewProjectService.selectTask(reviewProject);
        return getDataTable(list);
    }

    /**
     * 查询所有评审结果
     */
    @PreAuthorize("@ss.hasPermi('group:group:list')")
    @GetMapping("/selectAllScore")
    public TableDataInfo selectAllScore(ReviewProject reviewProject) {
        startPage();
        List<ProjectData> list = reviewProjectService.selectAllScore(reviewProject);
        return getDataTable(list);
    }


    /**
     * 根据id查询专家的评审项目及分数
     */
    @PreAuthorize("@ss.hasPermi('group:group:list')")
    @GetMapping("/selectScore/{id}")
    public AjaxResult selectScore(@PathVariable("id") Long id) {
        return AjaxResult.success(reviewProjectService.selectScore(id));
    }

    /**
     * 查看个人审评结果
     */
    @PreAuthorize("@ss.hasPermi('group:group:list')")
    @GetMapping("/selectMyScore")
    public TableDataInfo selectMyScore(ReviewProject reviewProject) {
        startPage();
        List<ProjectData> list = reviewProjectService.selectMyScore(reviewProject);
        return getDataTable(list);
    }
    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:list')")
    @GetMapping("/getAllList")
    public AjaxResult getAllList(ReviewProject reviewProject) {
        System.out.println(reviewProject.getGroupId());
        List<ReviewProject> list = reviewProjectService.getAllList(reviewProject);
        return AjaxResult.success(list);
    }
    /**
     * 按小组Id查询该小组的项目数据
     */
    @PreAuthorize("@ss.hasPermi('system:project:list')")
    @GetMapping("/selectProByid/{groupId}")
    public AjaxResult selectProByid(ReviewProject reviewProject, Long groupId) {
        startPage();
        List<ProjectData> list = reviewProjectService.selectProByid(reviewProject,groupId);
        return AjaxResult.success(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReviewProject reviewProject) {
        List<ReviewProject> list = reviewProjectService.selectReviewProjectList(reviewProject);
        ExcelUtil<ReviewProject> util = new ExcelUtil<ReviewProject>(ReviewProject.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(reviewProjectService.selectReviewProjectById(id));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('system:project:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReviewProject reviewProject) {
        return toAjax(reviewProjectService.insertReviewProject(reviewProject));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('system:project:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReviewProject reviewProject) {
        return toAjax(reviewProjectService.updateReviewProject(reviewProject));
    }

    /**
     * 评审分数
     */
    @PreAuthorize("@ss.hasPermi('system:project:edit')")
    @Log(title = "分数", businessType = BusinessType.UPDATE)
    @PutMapping("/updataScore")
    public AjaxResult updataScore(@RequestBody ReviewProject reviewProject) {
        return toAjax(reviewProjectService.updateReviewScore(reviewProject));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('system:project:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(reviewProjectService.deleteReviewProjectByIds(ids));
    }
}
